<%-- 
    Document   : yqxm
    Created on : 2016-7-20, 19:46:14
    Author     : cxhd
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../../link.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>仪器与项目匹配--通道号</title>
    </head>

    <style type="text/css">
        *{margin:0;padding:0;}
        .content_x{
            position: relative;
            width: 100%;
            height: 100%;
        }
        .search_x{
            position: relative;
            width: 100%;
            height:50px;
            border-bottom: 1px #23527c dashed;
        }
        .search_content{
            position: absolute;
            overflow: auto;
            top: 50px;
            bottom: 30px;
            width: 100%;
        }
        .mypage{
            position: absolute;
            bottom: 0px;
            width: 100%;
            margin: 0px;
        }
    </style>
</head>
<body ng-app="yqxm" ng-controller="ppManager" style="font-family: 微软雅黑;height: 100%;overflow: hidden" ng-controller="mainCtrl">
    <div class="col-lg-12" style="margin-top: 20px;">
        <div class="panel panel-default">
            <div class="panel-heading">
                <div  class="text-success" style="font-weight: bold;font-size: 16px;float: left">设备项目匹配</div>
                <div style="float: left;margin-left: 100px; width: 200px">
                    <select  class="form-control" ng-change="changeSelect(selectdDevice)" ng-model="selectdDevice" ng-options="x.DEVICEMODEL for x in pdts"></select>

                </div>
                <div style="float: left;margin-top: 10px;font-size: 14px;">  请选择设备</div>
                <div style="clear: both"></div>
            </div>
            <table id="main" class="table">
                <tr>
                    <td width="330px" style="border-right: 1px #23527c dashed">

                        <div class="content_x">
                            <div class="search_x">
                                <table style="width:100%">
                                    <tr>
                                        <td style="width:70px;"><label class="text-primary" style="font-weight: bold;font-size: 16px;">项目列表</label></td>
                                        <td valign="top">
                                            <div class="form-group">
                                                <input ng-keypress="keySearch($event)" type="text" ng-model="TESTID" value="" placeholder="查询..." class="form-control" />
                                            </div>
                                        </td>
                                        <td valign="middle" style="width:70px;">
                                            <button ng-click="getLisTestByT()"  class="btn btn-sm btn-success">查询</button>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="search_content">
                                <table  class="table table-striped table-bordered  table-hover"   >
                                    <tr>
                                        <th class="table-id"><input type="checkbox"></th>
                                        <th class="table-title">项目代码</th>
                                        <th class="table-title">项目名</th>

                                    </tr>
                                    <tr  ng-repeat="test in tests" ng-click="checkTest($index)">
                                        <td><input type="checkbox" ng-model="test.check"></td>
                                        <td>{{test.TESTID}}</td>
                                        <td>{{test.CHINESENAME}}</td>   
                                    </tr>
                                </table>
                            </div>
                            <div class="mypage" style="width: 100%;text-align: center">
                                <pagination ng-change="pageChanged()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data.currentPage" items-per-page="data.pageSize" total-items="data.bigTotalItems" ng-model="data.bigCurrentPage" max-size="data.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                            </div>
                        </div>
                    </td>
                    <td style="border-right: 1px #23527c dashed">
                        <div class="content_x">
                            <div class="search_x">
                                <table style="width:100%">
                                    <tr>

                                        <td valign="top">
                                            <label  class="text-info" style="font-weight: bold;font-size: 16px;">当前设备:<span class="info" ng-bind="DEVICENAME"></span></label>
                                            <button ng-disabled="!selectdDevice"  class="btn btn-sm btn-info"  ng-click="addPpDeviceTest()"><i class="fa fa-plus"></i>添加项目</button>

                                        </td>

                                        <td valign="middle" style="width:70px;">
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="search_content">
                                <table  class="table table-striped table-bordered  table-hover"   >
                                    <tr>
                                        <!--<th class="table-id">仪器名</th>-->
                                        <th class="table-title" style="width:60px;word-break:keep-all;
                                            white-space:nowrap;
                                            overflow:hidden;
                                            text-overflow:ellipsis;">项目名</th>
                                        <th class="table-title">项目代码 </th>
                                        <!--                                <th class="table-title">通道号</th>-->
                                        <th class="table-title">打印序号</th>
                                        <th class="table-title">单位 </th>
                                        <th class="table-title">男最低</th>
                                        <th class="table-title">男最高</th>
                                        <th class="table-title">女最低</th>
                                        <th class="table-title">女最高</th>
                                        <th class="table-title">默认值</th>
                                        <th class="table-title">留小数位</th>
                                        <th class="table-title">样本类型</th>
                                        <th class="table-title">操作</th>
                                    </tr>
                                    <tr  ng-repeat="ppdt in ppdts" >
                                        <!--<td>{{ppdt.DEVICENAME}}</td>-->
                                        <td title="{{ppdt.CHINESENAME}}" ><div style="width:120px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{ppdt.CHINESENAME}}</div></td>
                                        <td title="{{ppdt.TESTID}}"><div style="width:60px; white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">{{ppdt.TESTID}}</div></td>

                                        <td><input type="text" ng-model="ppdt.DATA1" style="width:40px"></td>

                                        <td><select ng-model="ppdt.UNIT" ng-options=" unit.UNITNAME as unit.UNITNAME for unit  in units" >

                                            </select>   </td>
                                        <td><input type="text" ng-model="ppdt.MREFLO0" style="width:40px"></td>
                                        <td><input type="text" ng-model="ppdt.MREFHI0" style="width:40px"></td>

                                        <td><input type="text" ng-model="ppdt.FREFLO0" style="width:40px"></td>
                                        <td><input type="text" ng-model="ppdt.FREFHI0" style="width:40px"></td>
                                        <td><input type="text" ng-model="ppdt.DATA2" style="width:40px"></td>
                                        <td><input type="text" ng-model="ppdt.Decimalplace" style="width:40px"></td>
                                        <td>
                                            <select ng-model="ppdt.SAMPLETYPE" ng-options="sam.SAMPLEDESCRIBE as sam.SAMPLEDESCRIBE for sam in sams"   style="width: 50px" >
                                                <!--                                                <option  value="">不选样本</option>-->
                                            </select> 
                                            <!--                                            <input type="text" ng-model="ppdt.SAMPLETYPE" style="width:40px">-->
                                        </td>

                                        <td><button ng-click="deletePp(ppdt)" class="btn btn-danger btn-xs"><span class="fa fa-bolt"></span>&nbsp;删除</button> 
                                            <button class="btn btn-success btn-xs" ng-click="updatePp(ppdt)"><span class="fa fa-save"></span>保存</button>
                                            <button class="btn btn-success btn-xs" ng-click="updateFw(ppdt)"><span class="fa fa-save"></span>范围</button>

                                            <!--<button class="btn m-b-xs btn-sm btn-success btn-addon" ng-click="updatePri(ppdt)">修改打印次序</button>-->
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <div class="mypage" style="width: 100%;text-align: center">
                                <!--<pagination ng-change="pageChanged_zjb()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="zjb.currentPage" items-per-page="zjb.pageSize" total-items="zjb.bigTotalItems" ng-model="zjb.bigCurrentPage" max-size="zjb.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>-->
                                <pagination ng-change="pageChanged2()" previous-text="上一页" next-text="下一页" first-text="第一页" last-text="最后一页" ng-model="data2.currentPage" items-per-page="data2.pageSize" total-items="data2.bigTotalItems" ng-model="data2.bigCurrentPage" max-size="data2.maxSize" class="pagination-sm" boundary-links="true" rotate="false" num-pages="numPages"></pagination>

                            </div>
                        </div>
                    </td>

                </tr>
            </table>

        </div>
    </div>


    <div class="modal fade mode-fw" id="mode3" role="dialog" aria-labelledby="gridSystemModalLabel">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" ng-click="CloseModel()"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="gridSystemModalLabel">添加范围值</h4>
                </div>
                <div class="modal-body" style="height: 400px; overflow: auto">
                    <table>
                        <tr>
                            <td>年龄小：</td>
                            <td><input type="text" style="width:100px;"  ng-model="range.min_age"></td>
                             <td>年龄大：</td>
                            <td><input type="text" style="width:100px;"  ng-model="range.max_age"></td>
                            
                              <td>性别：</td>
                            <td><input type="text" style="width:100px;" ng-model="range.sex"></td>
                             <td>范围值小：</td>
                            <td><input type="text" style="width:100px;" ng-model="range.min_val"></td>
                             <td>范围值大</td>
                            <td><input type="text" style="width:100px;" ng-model="range.max_val"></td>
                            <td>
                                <div class="col-lg-2" ><button style="margin-left: 10px;" ng-click="addRange()" class="btn btn-success btn-sm " >添加</button></div>
                            </td>
                        </tr>
                        
                    </table>
<!--                    <div class="col-lg-2"></div>
                    <div class="col-lg-2"><input type="text" placeholder="年龄（大）" ng-model="range.max_age"></div>
                    <div class="col-lg-2"><input type="text" placeholder="性别" ng-model="range.sex"></div>
                    <div class="col-lg-2"><input type="text" placeholder="范围值（小）" ng-model="range.min_val"></div>
                    <div class="col-lg-2"><input type="text" placeholder="范围值（大）" ng-model="range.max_val"></div>-->
                    <!--<div class="col-lg-2" ><button style="margin-left: 30px;" ng-click="addRange()" class="btn btn-success btn-sm " >添加</button></div>-->
                    <table class="table  table-bordered" style="margin-top: 10px;">
                        <tr>
                            <td>年龄</td>
                            <td>性别</td>
                            <td>范围</td>
                            <td>其他</td>
                        </tr>
                        <tr ng-repeat="item in ranges" >
                            <td>{{item.min_age}}~{{item.max_age}}</td>
                            <td>{{item.sex}}</td>
                            <td>{{item.min_val}}~{{item.max_val}}</td>
                            <td style="width:80px;"><button ng-click="deleteRange($index)" class="btn btn-danger btn-xs">删除</button></td>
                        </tr>
                    </table>

                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-dismiss="modal" ng-click="CloseModel()">关闭</button>
                    <!--<button  ng-click="addZT('replace')"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;替换</button>-->
                    <button  ng-click="saveRange()"  type="button" class="btn btn-primary"><span class="fa fa-save"></span>&nbsp;&nbsp;保存</button>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div>
</body>

<script>
    angular.module("yqxm", ['baseModule', 'ui.bootstrap'])
            .controller("ppManager", function ($scope, $http, base) {
                $scope.DEVICENAME = "";
                $scope.getLisDevices = function () {//仪器显示
                    base.post("pp/getLisDevices").get(function (data) {
                        console.log(data);
                        if (data) {
                            $scope.pdts = data;
//                         $scope.DEVICEID=data[0].DEVICEID;
//                         $scope.DEVICENAME=data[0].DEVICENAME;
//                         $scope.$apply();
                        }
                    })
                }
                $scope.getLisDevices();
                $scope.getSamp = function () {//样本类型显示
                    base.post("pp/getLisSam").get(function (data) {
                        if (data) {
                            $scope.sams = data;
//                         $scope.$apply();
                        }
                    })
                }
                $scope.getSamp();

                $scope.data = {currentPage: 1};
                $scope.setPage = function (pageNo) {
                    $scope.data.currentPage = pageNo;
                };
                $scope.pageChanged = function () {
                    $scope.getLisTestByT();
                };
                $scope.data.maxSize = 1;
                $scope.data.bigTotalItems = 20;
                $scope.data.bigCurrentPage = 1;
                $scope.data.pageSize = 10;

//             $scope.getLisTest=function(){//通过样本类型筛选项目
//                 base.post("pp/getLisTest",{PK:$scope.PK1,pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage}).get(function(data){
//                     if(data){
//                         $scope.tests=data.list;
//                           $scope.data.bigTotalItems = data.totalRow; 
////                         $scope.$apply();
//                     }
//                 })
//             }


                $scope.TESTID = "";
                $scope.getLisTestByT = function () {//通过项目代码筛选项目
                    base.post("citemtest/getLisTestByPy", {PK: $scope.PK1, TESTID: $scope.TESTID, pageSize: $scope.data.pageSize, currentPage: $scope.data.currentPage}).get(function (data) {
//                     console.log(data);
                        if (data) {
                            $scope.tests = data.list;
                            $scope.data.bigTotalItems = data.totalRow;
//                         $scope.$apply();
                        }
                    })
                }
                $scope.changeSelect = function (item) {
                    //console.log($scope.selectDevice);
                    $scope.checkDevice(item);
                }
                $scope.keySearch = function (event) {
                    if (event.keyCode == 13) {
                        $scope.getLisTestByT();
                    }
                }
                $scope.getLisTestByT();
                $scope.checkDevice = function (tmp) {
                    console.log(tmp);
                    $scope.DEVICEID = tmp.DEVICEID;
                    $scope.DEVICENAME = tmp.DEVICENAME;
                    $scope.DEVICEPK = tmp.DEVICEPK;
                    $scope.getPpDeviceT();
                }
                $scope.checkTest = function (index) {//点击行选择复选框
                    if ($scope.tests[index].check) {
                        $scope.tests[index].check = false;
                    } else {
                        $scope.tests[index].check = true;
                    }
                }
                $scope.checkT = [];
                $scope.addPpDeviceTest = function () {
                    if ($scope.DEVICENAME == "") {
                        alert("请选择匹配仪器");
                        return;
                    }
                    for (var i = 0; i < $scope.tests.length; i++) {//获取选中的项目
                        if ($scope.tests[i].check) {
                            $scope.checkT.push($scope.tests[i]);
                        }
                    }
                    if ($scope.checkT.length == 0) {
                        alert("请先为仪器选择项目在匹配");
                        return;
                    }
                    var checktes = JSON.stringify($scope.checkT);
                    base.post("pp/savePpDeviceTest", {TESTS: checktes, DEVICEID: $scope.DEVICEID, DEVICEPK: $scope.DEVICEPK}).get(function (data) {

                        if (data == 'true') {

                            $scope.getPpDeviceT();
                            $scope.checkT = [];
                        }
                    })
                }
                $scope.data2 = {currentPage: 1};

                $scope.pageChanged2 = function () {
                    $scope.getPpDeviceT();
                };
                $scope.data2.maxSize = 1;
                $scope.data2.bigTotalItems = 20;
                $scope.data2.bigCurrentPage = 1;
                $scope.data2.pageSize = 10;
                $scope.getPpDeviceT = function () {
                    base.post("pp/getPpDeviceTest", {DEVICEID: $scope.DEVICEID, pageSize: $scope.data2.pageSize, currentPage: $scope.data2.currentPage}).get(function (data) {
                        console.log(data);
                        if (data) {
                            $scope.ppdts = data.list;
                            $scope.data2.bigTotalItems = data.totalRow;
//                        $scope.$apply();
                        }
                    })
                }
                $scope.getPpDeviceT();

                $scope.deletePp = function (tmp) {
                    base.post("pp/deletePpDeviceTest", {DEVICEID: tmp.DEVICEID, TESTID: tmp.TESTID}).get(function (data) {
                        if (data == 'true') {
                            $scope.getPpDeviceT();
                        }
                    })
                }

                $scope.updatePp = function (ppdt) {
                    base.post("pp/updatePpDeviceTest", ppdt).get(function (data) {
                        if (data == 'true') {
                            steveAl("保存成功", 1000)
                            $scope.getPpDeviceT();
                        }
                    })
                }
                $scope.ranges = [];
                $scope.addRange = function () {
                    if ($scope.range.min_age) {
                        $scope.ranges.push($scope.range);
                        $scope.range={};
                    }
                }
                $scope.deleteRange = function(index){
                     $scope.ranges.splice(index,1);
                }
                $scope.saveRange=function(){
                      base.post("pp/saveRanges",{pk:$scope.update_pk,range:escape(angular.toJson($scope.ranges))}).get(function(data){
                        if(data=='true'){
                            steveAl("保存成功",1000);
                            $(".mode-fw").modal('hide');
                        }
                    })
                }
//             $scope.updatePri=function(ppdt){
//                 base.post("pp/updatePpDeviceTest",{PK:ppdt.PK,DEVICEID:ppdt.DEVICEID,TESTID:ppdt.TESTID,DATA2:ppdt.DATA2}).get(function(data){
//                     if(data=='true'){
//                         alert("保存成功");
//                      $scope.getPpDeviceT();  
//                    }
//                 })
//             }
                $scope.updatTestPK = function () {
                    base.post("pp/updateTestpk").get(function (data) {
                        if (data) {
                            alert("修改成功！");
                        }
                    })
                }
                $scope.getUnit = function () {//单位
                    base.post("lisTes/getUnit").get(function (data) {
                        if (data) {
                            $scope.units = data;
                        }
                    })
                }
                $scope.updateFw = function (item) {
                    
                    $scope.update_pk = item.PK;
                   $scope.ranges=[];
                    base.post("pp/getRanges",{pk:item.PK}).get(function(data){
                        if(data&&data!="false"&&data!="null"){
                            try{
                            $scope.ranges = JSON.parse(unescape(data));
                        }catch(e){
                            $scope.ranges=[];
                        }
                        }
                    })
                    $(".mode-fw").modal("show");
                }

                $scope.getUnit();
            })

    function autoHeight() {
        var bHeight = $(window).height();


        $("#main").height(bHeight - 85);
        console.log(bHeight - 85);

    }
    autoHeight();


    $(window).resize(function () {
        autoHeight();
    });
</script>


</html>
